<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org"
	  xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/css/bootstrap-select.min.css">
<body class="gray-bg">
<div class="container-div">
	<div class="row">
		<div class="col-sm-12 search-collapse">
			<form id="role-form">
				<div class="select-list">
					<ul>
						<li class="select-time">
							<label>开始时间： </label>
							<input type="text" class="time-input" id="beginTime" readonly placeholder="开始日期" th:value="${beginTime}" name="beginTime"/>
							<span>-</span>
							<input type="text" class="time-input" id="endTime" th:value="${endTime}" readonly placeholder="结束日期" name="endTime"/>
						</li>
						<li >
							<input type="hidden" name="stationCodes" id="stationCodes">

							站名：
							<select id="stationCode"  name="stationCode" class="selectpicker show-tick " multiple title="请选择">
								<option th:each="sta : ${stations}" th:text="${sta.name}" th:value="${sta.num}"></option>
							</select>
						</li>
						<li>
							<a class="btn btn-primary btn-rounded btn-sm" onclick="reLoad()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							<a class="btn btn-warning btn-rounded btn-sm" onclick="reReset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
						</li>
					</ul>
				</div>
			</form>
		</div>

		<div class="btn-group-sm hidden-xs" id="toolbar" role="group">
			<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="statistics:operation:export">
				<i class="fa fa-download"></i> 导出
			</a>
		</div>

		<div class="col-sm-12 select-table table-striped">
			<table id="bootstrap-table" data-mobile-responsive="true"></table>
		</div>
	</div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var detailFlag = [[${@permission.hasPermi('statistics:operation:detail')}]];
    var prefix = ctx + "statistics/operation";
    $(function() {
        var options = {
            url: prefix + "/list",
            exportUrl: prefix + "/export",
            queryParams: queryParams,
            //sortName: "stakeCode",
            modalName: "运营统计报表",
            search: false,
            pagination : false,//是否分页
            showExport: false,
            showFooter: true,//开启列计算函数
            columns: [
                {
                    field: 'stationCode',
                    title: '站号',
                    visible: false,
                    footerFormatter: function(){
                        return "-";
                    }
                },
                {
                    field: 'stationName',
                    title: '站名',
                    width:'25%',
                    footerFormatter: function(){
                        return "合计";
                    }
                },
                {
                    field: 'chargeDn',
                    title: '充电电量(度)',
                    width:'25%',
					footerFormatter: function(value){
                        var count = 0;
                        for (var i in value){
                            count += parseFloat(value[i].chargeDn);
						}
						return count;
					}
                },
                {
                    field: 'chargeMoney',
                    title: '充电金额(元)',
                    width:'25%',
                    footerFormatter: function(value){
                        var count = 0;
                        for (var i in value){
                            count += parseFloat(value[i].chargeMoney);
                        }
                        return count;
                    }
                },
                {
                    title: '操作',
                    width:'25%',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-info btn-xs ' + detailFlag + '" href="#" onclick="detail(\'' + row.stationCode + '\')"><i class="fa fa-list-ul"></i>明细</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    //搜索
    function reLoad() {
        var beginTime = $('#beginTime').val();
        var endTime = $('#endTime').val();
        if (beginTime === '' || endTime === ''){
            $.modal.alertWarning("开始日期或结束日期不能为空");
            return;
		}
        $('#bootstrap-table').bootstrapTable('refresh');
    }

    //重置
    function reReset() {
        $('#beginTime').val('');
        $('#endTime').val('');
        $("#stationCode").selectpicker('deselectAll');
    }

    /*运营详细列表*/
    function detail(stationCode) {
        var url = prefix + '/detail/' + stationCode+","+$('#beginTime').val()+","+$('#endTime').val();
        createMenuItem(url, "运营明细");
    }

    //下拉框改变的时候赋值
    $("#stationCode").change(function(){
        $("input[name=stationCodes]").val($("#stationCode").val());
    })

    function queryParams() {
        return {
            stationCodes:   $("#stationCodes").val(),
            beginTime:   $("#beginTime").val(),
            endTime:   $("#endTime").val()
        };
    }
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/js/bootstrap-select.min.js"></script>
</body>
</html>